package main

import (
	"fmt"
	"rabbitmq/mq"
	"strconv"
	"time"
)

var (
	contentChan = make(chan string, 100)
)

func main() {
	rabbitMqConf := mq.ConfigRb{
		QueueName:    "qutest",
		RoutingKey:   "rttest",
		ExchangeName: "extest",
		ExchangeType: "direct",
		User:         "admin",
		PassWord:     "admin",
		Host:         "192.168.2.114",
		Port:         5672,
	}
	rb, err := mq.New(rabbitMqConf)
	if err != nil {
		panic(err)
	}
	//生产消息
	go func() {
		i := 0
		for {
			contentChan <- "测试消息" + strconv.Itoa(i)
			i++
			time.Sleep(time.Millisecond * 500)
		}
	}()
	go func() {
		if err := rb.Producer(contentChan); err != nil {
			panic(err)
		}
	}()

	go func() {
		err := rb.Receiver()
		if err != nil {
			panic(err)
		}
		for {
			select {
			case v := <-rb.ReceiveChan:
				fmt.Printf("%p", &rb.ReceiveChan)
				fmt.Println("读取消息:", string(v.Body))
				v.Ack(true)
			}
		}
	}()
	for {

	}
}
